<!--
  Copyright © 2016 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="side-panel top clearfix">
  <h1 class="pull-left">我的管道</h1>
  <ul ng-if="ListController.pipelineList.length > 0" class="list-unstyled list-inline pull-left">
    <li>
      <span>{{ ListController.pipelineList.length }}</span>
      <span>总计</span>
    </li>
    <li>
      <i class="fa text-light-running"></i>
      <span>
        {{ ListController.statusCount.running }}
      </span>
      <span>运行中</span>
    </li>
    <li>
      <i class="fa text-outline-grey"></i>
      <span>
        {{ ListController.statusCount.draft }}
      </span>
      <span> 草稿</span>
    </li>
  </ul>
  <cask-resource-center-button></cask-resource-center-button>
</div>

<div class="my-pipelines">
  <div ng-if="ListController.pipelineList.length > 0 && ListController.pipelineListLoaded">
    <div class="table-responsive">
      <table class="table" cask-sortable>
        <thead>
          <tr ng-class="{'sort-enabled': ListController.pipelineList.length>0}">
            <th data-predicate="name">管道 名称</th>
            <th data-predicate="artifact.name">类型</th>
            <th data-predicate="displayStatus">状态</th>
            <th data-predicate="_stats.numRuns">总运行 Runs</th>
            <th data-predicate="_stats.lastStartTime" data-predicate-default>最后 开始时间</th>
            <th data-predicate="duration">持续时间</th>
            <th data-predicate="_stats.nextRun">下次运行 </th>
            <th skip-sort></th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="pipeline in ListController.pipelineList | orderBy:sortable.predicate:sortable.reverse | myPaginate:ListController.currentPage">
            <td class="pipeline-name">
              <a ui-sref="hydrator.detail({ pipelineId: pipeline.name })" ng-if="::!pipeline.isDraft">
                {{::pipeline.name}}
              </a>
              <a ui-sref="hydrator.create({ draftId: pipeline.id, type:pipeline.artifact.name })" ng-if="::pipeline.isDraft">
                {{::pipeline.name}}
              </a>
            </td>
            <td>
              <span class="icon-{{ ListController.GLOBALS.iconArtifact[pipeline.artifact.name] }}"></span>
              <span>{{ ::ListController.GLOBALS.artifactConvert[pipeline.artifact.name] }}</span>
            </td>
            <td>
              <span class="status-bubble" ng-class="ListController.MyPipelineStatusMapper.getStatusIndicatorClass(pipeline.displayStatus)"></span>
              <span>{{ pipeline.displayStatus }}</span>
            </td>
            <td>
              <span ng-if="pipeline._stats.numRuns !== 'N/A'">{{ pipeline._stats.numRuns }}</span>
              <span ng-if="pipeline._stats.numRuns === 'N/A'"> &mdash; </span>
            </td>
            <td>
              <span ng-if="pipeline._stats.lastStartTime === 'N/A' || !pipeline._stats.lastStartTime"> &mdash; </span>
              <span ng-if="pipeline._stats.lastStartTime !== 'N/A'">{{ pipeline._stats.lastStartTime * 1000 | amDateFormat: 'MM/DD/YY h:mm:ss A' }}</span>
            </td>

            <td>
              <span class="metric-value" ng-if="!pipeline.duration"> &mdash; </span>
              <span class="metric-value" ng-if="pipeline.duration" ng-bind="pipeline.duration"></span>
            </td>

            <td>
              <span ng-if="!pipeline._stats.nextRun"> &mdash; </span>
              <span ng-if="pipeline._stats.nextRun !== 'N/A'">{{ pipeline._stats.nextRun | amDateFormat: 'MM/DD/YY h:mm:ss A' }}</span>
            </td>

            <td>
              <span class="fa fa-trash text-danger delete-draft" ng-if="pipeline.isDraft" ng-click="caskConfirm()" cask-confirmable="ListController.deleteDraft(pipeline.id)" confirmable-modal-class="hydrator-modal center" data-confirmable-content="Are you sure you want to delete the draft '<strong>{{ pipeline.name }}</strong>'?"></span>
              <span class="fa fa-trash text-danger delete-draft" ng-if="!pipeline.isDraft" ng-click="caskConfirm()" cask-confirmable="ListController.deleteApp(pipeline.name)" confirmable-modal-class="hydrator-modal center" data-confirmable-content="Are you sure you want to delete the pipeline '<strong>{{ pipeline.name }}</strong>'?"></span>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <div class="text-center" ng-if="ListController.pipelineList.length > 10">
      <uib-pagination total-items="ListController.pipelineList.length" ng-change="ListController.goToPage()" ng-model="ListController.currentPage"></uib-pagination>
    </div>

  </div>

  <div ng-if="ListController.pipelineList.length === 0 && ListController.pipelineListLoaded">
    <div class="well well-lg text-center">
      <h4>You haven't published any pipelines yet - start by adding one.</h4>
    </div>
  </div>

  <div ng-if="!ListController.pipelineListLoaded">
    <div class="well well-lg text-center">
      <h3>
        <span class="fa fa-spinner fa-spin fa-2x"></span>
      </h3>
    </div>
  </div>
</div>
